package cc.orange.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cc.orange.entity.AllGradeInfo;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cc.orange.R;

public class GradeListItemAdapter extends BaseQuickAdapter<AllGradeInfo.DataDTO, GradeListItemAdapter.GradeListItemAdapterViewHolder> {

    private List<AllGradeInfo.DataDTO> data;
    public GradeListItemAdapter(@Nullable List<AllGradeInfo.DataDTO> data) {
        super(R.layout.item_grade_list_item, data);
        this.data = data;
    }

    public void updateData(List<AllGradeInfo.DataDTO> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(@NonNull GradeListItemAdapterViewHolder helper, AllGradeInfo.DataDTO item) {
        helper.bindData(item);
    }

    class GradeListItemAdapterViewHolder extends BaseViewHolder{

        private TextView tvLevel, tvEx, tvContent;
        private ImageView ivLevel;

        public GradeListItemAdapterViewHolder(View view) {
            super(view);
            tvLevel = view.findViewById(R.id.tv_level);
            tvEx = view.findViewById(R.id.tv_ex);
            tvContent = view.findViewById(R.id.tv_conten);
            ivLevel = view.findViewById(R.id.iv_level);
        }

        public void bindData(AllGradeInfo.DataDTO data){
            tvLevel.setText(data.getLevel());
            tvEx.setText(data.getLevelNum()+"");
            tvContent.setText(data.getLevelShiro());
            switch (data.getLevel()) {
                case "LV.1" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv1).into(ivLevel);
                    break;
                case "LV.2" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv2).into(ivLevel);
                    break;
                case "LV.3" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv3).into(ivLevel);
                    break;
                case "LV.4" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv4).into(ivLevel);
                    break;
                case "LV.5" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv5).into(ivLevel);
                    break;
                case "LV.6" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv6).into(ivLevel);
                    break;
                case "LV.7" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv7).into(ivLevel);
                    break;
                case "LV.8" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv8).into(ivLevel);
                    break;
                case "LV.9" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv9).into(ivLevel);
                    break;
                case "LV.10" :
                    Glide.with(itemView.getContext()).load(R.drawable.icon_lv10).into(ivLevel);
                    break;
            }
        }
    }
}
